<style>
/* 	td { */
/* 		width:100px; */
/* 	} */
</style>
<script>
	//音乐控制
// 	function operationMusic(value,sn) {
// 		 $.post('devOperation.do?operationMusic',{value:value,sn:sn},function(result){
//             printLog(result);
//          },'json');
// 	}
	//电视控制
// 	function operationMusic(value,sn) {
// 		 $.post('devOperation.do?operationMusic',{value:value,sn:sn},function(result){
//             printLog(result);
//          },'json');
// 	}
	
	//
	function operationComponent(componentType,id) {
		
		var comp = {};
		switch (componentType) {
		case 'music':
			comp = createMusic(id);
			break;
		case 'tv':
			comp = createTv(id);
			break;
		case 'ac':
			comp = createAc(id);
			break;
		case 'dimmer':
			comp = createDimmer(id);
			break;
		case 'node':
			comp = createNode(id);
			break;
		default:
			break;
		}
		printLog(comp);
		jmaxAjax('devOperation.do?sendWriteCmd',{id:'${(roomItem.deviceId)!}',type:componentType,cmdData:JSON.stringify(comp)});
// 		$.post('devOperation.do?sendWriteCmd',{id:'${(roomItem.deviceId)!}',type:componentType,cmdData:JSON.stringify(comp)},function(result){
// 	       if(!result.success) {
// 	    	   showMsg(result.msg);
// 	       }
// 	    },'json');
	}
	
	function createMusic(id) {
		var music = {
		 	addr: $('#musicAddr'+id).val(),
            channel: $('#musicChannel'+id).val(),
            volume: $('#musicVolume'+id).spinner('getValue'),
            ch: $('#musicCh'+id).numberspinner('getValue'),
            input: $('#musicInput'+id).numberspinner('getValue'),
            item: $('#musicItem'+id).combobox('getValue'),
            power: $('#musicPower'+id).combobox('getValue')
		};
		return music;
	}
	
	function createTv(id) {
		var tv = {
		 	addr: $('#tvAddr'+id).val(),
            channel: $('#tvChannel'+id).val(),
            volume: $('#tvVolume'+id).spinner('getValue'),
            ch: $('#tvCh'+id).numberspinner('getValue'),
            input: $('#tvInput'+id).numberspinner('getValue'),
            item: $('#tvItem'+id).combobox('getValue'),
            power: $('#tvPower'+id).combobox('getValue')
		};
		return tv;
	}
	
	function createAc(id) {
		var ac = {
		 	addr: $('#acAddr'+id).val(),
            channel: $('#acChannel'+id).val(),
            power: $('#acPower'+id).combobox('getValue'),
            mode: $('#acMode'+id).combobox('getValue'),
            fan: $('#acFan'+id).combobox('getValue'),
            temp: $('#acTemp'+id).numberspinner('getValue')
           
		};
		return ac;
	}
	
	function createDimmer(id) {
		var dimmer = {
		 	addr: $('#dimmerAddr'+id).val(),
            channel: $('#dimmerChannel'+id).val(),
            status: $('#dimmerStatus'+id).combobox('getValue'),
            freq: $('#dimmerFreq'+id).numberspinner('getValue'),
            delay: $('#dimmerDelay'+id).numberspinner('getValue'),
            value: $('#dimmerValue'+id).spinner('getValue')
		};
		return dimmer;
	}
	
	function createNode(id) {
		var node = {
		 	addr: $('#nodeAddr'+id).val(),
            channel: $('#nodeChannel'+id).val(),
            status: $('#nodeStatus'+id).combobox('getValue'),
            freq: $('#nodeFreq'+id).numberspinner('getValue'),
            delay: $('#nodeDelay'+id).numberspinner('getValue')
		};
		return node;
	}
	
	function selectRoomScene(v) {
		printLog(v);
		var scene = {
				"number": v.value
		};
		$.post('devOperation.do?sendWriteCmd',{id:'${(roomItem.deviceId)!}',type:'scene',cmdData:JSON.stringify(scene)},function(result){
		     showMsg(result.msg);
		    },'json');
	}
</script>
<div class="easyui-layout" data-options="fit:true" id="editRoomLayout">
    <div data-options="region: 'center', border:false">
		<table cellpadding="5">
			<input id="roomId" name="id" type="hidden" value="${(roomItem.id)!}" />
			<tr>
				<td class="tbLabel">所属区域:</td>
				<td>
					<@eu.comboBox disabled="true" id="roomServiceArea" url="common.do?loadComboBox&key=SERVICE_AREA&value=${(roomItem.serviceArea)!}" name="serviceArea" />
				</td>
				<td style="width:200px">所属楼层:</td>
				<td style="width:200px">
					<@eu.comboBox disabled="true" id="roomFloor" url="common.do?loadComboBox&key=ROOM_FLOOR&value=${(roomItem.floor)!}" name="floor" />
				</td>
				
				<td style="width:200px">房间号:</td>
				<td style="width:200px">
					<input id="roomNo" name="roomNo"  class="easyui-validatebox textbox" readonly="readonly" value="${(roomItem.roomNo)!}"/>
				</td>
				
			</tr>
			<tr>
				<td class="tbLabel">房间类型:</td>
				<td>
					<@eu.comboBox disabled="true" id="operationRoomType" url="common.do?loadComboBox&key=ROOM_TYPE&text=${(roomItem.type)!}" name="type" required="true"/>
				</td>
				
				<td>房间状态:</td>
				<td>			
					<@eu.comboBox disabled="true" id="roomStatus" url="common.do?loadComboBox&key=ROOM_STATUS&value=${(roomItem.status)!}" name="status" required="true"/>
				</td>
				<td class="tbLabel">房间场景:</td>
				<td>
					<@eu.comboBox id="operationRoomScene" url="common.do?loadComboBox&key=ROOM_SCENE&value=${(roomItem.scene)!}" name="scene" required="true" onSelect="selectRoomScene(value)"/>
				</td>
			</tr>
			<tr>
				<td>房间名称:</td>
				<td>
					<input id="roomName" name="name"  class="easyui-validatebox textbox" readonly="readonly" value="${(roomItem.name)!}"/>
				</td>
				<td>RCU设备:</td>
				<td>
					<@eu.comboBox disabled="true" id="roomDeviceName" url="device.do?loadDevices&text=${(roomItem.deviceName)!}" name="deviceName" required="true"/>
				</td>
			</tr>
			<#list deviceLinkItems as dl>
				<#if dl.ltype=="music">
				<tr style="background-color: #c5dbf6;">
					<input id="musicAddr${dl.id}" type="hidden" value="${(dl.comp.addr)!}"/>
					<input id="musicChannel${dl.id}" type="hidden" value="${(dl.comp.channel)?default(0)}" />  
					<td>${dl.lid}:</td>
					<td>
						状态:<@eu.comboBox id="musicPower${dl.id}" width="100" url="common.do?loadComboBox&key=POWER_STATUS&value=${(dl.comp.power)!}" onSelect="operationComponent('music',${dl.id})"/>
					</td>
					<td>
						音量:<input id="musicVolume${dl.id}" class="easyui-slider" value="${(dl.comp.volume)!}" data-options="showTip:true,onChange:function(newValue,oldValue) {operationComponent('music',${dl.id});}" /> 
					</td>
					<td>
						输入源:<input width="100" id="musicInput${dl.id}"  name="input" class="easyui-numberspinner" data-options="min:0,max:10,width:100,onChange:function(newValue,oldValue) {operationComponent('music',${dl.id});}" value="${(dl.comp.input)?default(0)}" />  
					</td>
					<td>
						频道:<input width="100" name="ch" id="musicCh${dl.id}" class="easyui-numberspinner" data-options="min:0,max:255,width:100,onChange:function(newValue,oldValue) {operationComponent('music',${dl.id});}" value="${(dl.comp.ch)?default(0)}" />  
					</td>
					<td>
						节目:	<@eu.comboBox width="100" id="musicItem${dl.id}" url="common.do?loadComboBox&key=PROGRAM_ITEM&value=${(dl.comp.item)?default(\"next\")}" onSelect="operationComponent('music',${dl.id})"/>
					</td>
				</tr>
			</#if>
			<#if dl.ltype=="tv">
				<tr style="background-color: #c5dbf6;">
					<input id="tvAddr${dl.id}" type="hidden" value="${(dl.comp.addr)!}"/>
					<input id="tvChannel${dl.id}" type="hidden" value="${(dl.comp.channel)?default(0)}" />  
					<td>${dl.lid}:</td>
					<td>
						状态:<@eu.comboBox id="tvPower${dl.id}" width="100" url="common.do?loadComboBox&key=POWER_STATUS&value=${(dl.comp.power)!}" onSelect="operationComponent('tv',${dl.id})"/>
					</td>
					<td>
						音量:<input id="tvVolume${dl.id}" class="easyui-slider" value="${(dl.comp.volume)!}" data-options="showTip:true,onChange:function(newValue,oldValue) {operationComponent('tv',${dl.id});}" /> 
					</td>
					<td>
						输入源:<input id="tvInput${dl.id}"  name="input" class="easyui-numberspinner" data-options="min:0,max:10,width:100,onChange:function(newValue,oldValue) {operationComponent('tv',${dl.id});}" value="${(dl.comp.input)?default(0)}" />  
					</td>
					<td>
						频道:<input name="ch" id="tvCh${dl.id}" class="easyui-numberspinner" data-options="min:0,max:255,width:100,onChange:function(newValue,oldValue) {operationComponent('tv',${dl.id});}" value="${(dl.comp.ch)?default(0)}" />  
					</td>
					<td>
						节目:	<@eu.comboBox width="100" id="tvItem${dl.id}" url="common.do?loadComboBox&key=PROGRAM_ITEM&value=${(dl.comp.item)?default(\"next\")}" onSelect="operationComponent('tv',${dl.id})"/>
					</td>
				</tr>
			</#if>
			<#if dl.ltype=="ac">
				<tr style="background-color: #c5dbf6;">
					<input id="acAddr${dl.id}" type="hidden" value="${(dl.comp.addr)!}"/>
					<input id="acChannel${dl.id}" type="hidden" value="${(dl.comp.channel)?default(0)}" />  
					<td>${dl.lid}:</td>
	           		<td>状态:<@eu.comboBox id="acPower${dl.id}" width="100" url="common.do?loadComboBox&key=POWER_STATUS&value=${(dl.comp.power)!}" onSelect="operationComponent('ac',${dl.id})"/></td>
					<td>
					      模式:<@eu.comboBox id="acMode${dl.id}" width="100" url="common.do?loadComboBox&key=AC_MODE&value=${(dl.comp.mode)!}" onSelect="operationComponent('ac',${dl.id})"/>
					  </td>
					  <td>
					      风速:<@eu.comboBox id="acFan${dl.id}" width="100" url="common.do?loadComboBox&key=AC_FAN&value=${(dl.comp.fan)!}" />
					  </td>
					  <td>
					  	温度:<input id="acTemp${dl.id}" class="easyui-numberspinner" data-options="min:16,max:31,width:100,onChange:function(newValue,oldValue) {operationComponent('ac',${dl.id});}" value="${(dl.comp.temp)!}" />  
					  </td>
				</tr>
			</#if>
			<#if dl.ltype=="dimmer">
				<tr style="background-color: #c5dbf6;">
					<input id="dimmerAddr${dl.id}" type="hidden" value="${(dl.comp.addr)!}"/>
					<input id="dimmerChannel${dl.id}" type="hidden" value="${(dl.comp.channel)?default(0)}" />  
					<td>
						${dl.lid}:
					</td>
					<td>
						状态:<@eu.comboBox width="100" id="dimmerStatus${dl.id}" url="common.do?loadComboBox&key=DIMMER_STATUS&value=${(dl.comp.status)?default(\"off\")}" onSelect="operationComponent('dimmer',${dl.id})" />
					</td>
					<td>
						亮度:<input name="value" id="dimmerValue${dl.id}" class="easyui-slider" value="${(dl.comp.value)?default(50)}" data-options="showTip:true,onChange:function(newValue,oldValue) {operationComponent('dimmer',${dl.id});}" />
					</td>
					<td>
						闪烁频率:<input id="dimmerFreq${dl.id}" class="easyui-numberspinner" data-options="min:0,max:255,width:100,onChange:function(newValue,oldValue) {operationComponent('dimmer',${dl.id});}" value="${(dl.comp.freq)?default(1)}" />秒/次  
					</td>
					<td>
						延迟时间:<input id="dimmerDelay${dl.id}" class="easyui-numberspinner" data-options="min:0,max:255,width:100,onChange:function(newValue,oldValue) {operationComponent('dimmer',${dl.id});}" value="${(dl.comp.delay)?default(0)}" />秒 
					</td>
				</tr>
			</#if>
			<#if dl.ltype=="node">
				<tr style="background-color: #c5dbf6;">
					<input id="nodeAddr${dl.id}" type="hidden" value="${(dl.comp.addr)!}"/>
					<input id="nodeChannel${dl.id}" type="hidden" value="${(dl.comp.channel)?default(0)}" />  
					<td>
						${dl.lid}:
					</td>
					<td>
						状态:<@eu.comboBox width="100" id="nodeStatus${dl.id}" url="common.do?loadComboBox&key=${(dl.comp.type)!'DIMMER'}_STATUS&value=${(dl.comp.status)?default(\"off\")}" onSelect="operationComponent('node',${dl.id})" />
					</td>
					<#if dl.comp.type=="LIGHTS">
					<td>
						闪烁频率:<input id="nodeFreq${dl.id}" class="easyui-numberspinner" data-options="min:0,max:255,width:100,onChange:function(newValue,oldValue) {operationComponent('node',${dl.id});}" value="${(dl.comp.freq)?default(1)}" />秒/次
					</td>
					<td>
						延迟时间:<input id="nodeDelay${dl.id}" class="easyui-numberspinner" data-options="min:0,max:255,width:100,onChange:function(newValue,oldValue) {operationComponent('node',${dl.id});}" value="${(dl.comp.delay)?default(0)}" />秒
					</td>
					</#if>
					
				</tr>
			</#if>
			</#list>
			
			
			
			<#assign h = {"music":"音乐", "tv":"电视","ac":"空调","node":"节点","dimmer":"调光"}>
			
		</table>
	</div>
</div>
